<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020-06-10
  Time: 16:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <%
        String path = request.getContextPath();
        // 获得项目完全路径（假设你的项目叫MyApp，那么获得到的地址就是

        //http://localhost:8080/SpringMVC01/）:
        String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <title>主页面</title>
    <base href=" <%=basePath%>">
    <!-- 引入样式  -->
    <link href="static/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
    <!-- 引入jQuery -->
    <script type="text/javascript" src="static/bootstrap-3.3.7-dist/jq/jquery-1.12.4.min.js"></script>
    <style type="text/css">
        .list li{
            list-style-type:none;//去掉圆点
            float:left;
            display: inline;//让li横向排列
        }

    </style>

    <script type="text/javascript">
        function button() {
            var txt;
            if (confirm("警告")) {
                txt = "您按了确定";
            } else {
                txt = "您按了取消";
            }
            alert(txt);
            document.getElementById("demo").innerHTML = txt;
        }



        $(function () {
            $("#testTab").on("click", ":button", function (event) {
                var txt;
                var date = "ID:" + $(this).closest("tr").find("td").eq(1).text() + "\n" +
                    "name:" + $(this).closest("tr").find("td").eq(2).text() + "\n" +
                    "password: " + $(this).closest("tr").find("td").eq(3).text() + "\n" +
                    "email:" + $(this).closest("tr").find("td").eq(4).text() + "\n" +
                    "role:" + $(this).closest("tr").find("td").eq(5).text() + "\n";
                if (confirm("删除提示"+ "\n" + date)){
                    txt = "您按了确定";
                } else {
                    txt = "您按了取消";
                }
                alert(txt);

                /*$("#text").val($(this).closest("tr").find("td").eq(0).text());*/
            })
        })

    </script>
</head>
<body>
<%--${information}<br>
${user.userName}<br>
${user.userPassword}<br>
${user.userEmail}<br>
${user.role}--%>

<%--
    显示登录的用户名和用户身份
    三元运算符，显示用户身份
--%>
<h3 align="right">${user.role eq 0? "管理员":"用户"} : ${user.userName}</h3>
<h3></h3>
<h2 align="center">用户信息</h2>
<div class="container">

    <!-- 按钮 -->
    <div class="row">
        <div class="col-md-4 col-md-offset-8">
            <button class="btn btn-info" id="emp_add_modal_btn">新增</button>
            <button class="btn btn-danger" id = "emp_delete_all_btn">删除</button>
        </div>
    </div>
    <!-- Stack the columns on mobile by making one full-width and the other half-width -->
    <div class="row">
        <div class="col-md-12">
            <table id="testTab" class="table table-bordered table-hover">
                <thead>
                    <tr>
                        <th>选定框</th>
                        <th>用户编号</th>
                        <th>用户名</th>
                        <th>用户密码</th>
                        <th>用户邮箱</th>
                        <th>用户身份</th>
                        <th>注册时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <c:forEach items="${users}" var="users">
                        <tr>
                            <td><input type="checkbox"></td>
                            <td>${users.userId}</td>
                            <td>${users.userName}</td>
                            <td>${users.userPassword}</td>
                            <td>${users.userEmail}</td>
                            <td>
                                <c:choose>
                                    <c:when test="${users.role  == 0}">
                                        管理员
                                    </c:when>
                                    <c:when test="${users.role  == 1}">
                                        用户
                                    </c:when>
                                </c:choose>
                            </td>
                            <td>注册时间</td>
                            <td>
                                <button class="btn btn-info btn-sm edit_btn">编辑</button>
                                <button class="btn btn-danger btn-sm delete_btn">删除</button>
                            </td>
                        </tr>
                    </c:forEach>
                </tbody>
            </table>
        </div>
        <div class="col-md-12">
            <table class="table table-bordered table-hover">

            </table>
        </div>
    </div>

    <%
        int currentPage = 1;
        Object currentPage01 = request.getAttribute("currentPage");
        if(currentPage01 != null){
            currentPage = (int)currentPage01;
        }

        int next = currentPage + 1;
        int prev = currentPage - 1;
    %>
    <div align="center">
        <ul class="list">
            <li><a href="user/page.do?currentPage=1">首页</a></li>
            <li><a href="user/page.do?currentPage=<%=prev %>">上一页</a></li>
            <li><a href="user/page.do?currentPage=<%=next %>">下一页</a></li>
            <li><a href="user/page.do?currentPage=${last }">尾页</a></li>
        </ul>
    </div>
</div>
</body>
</html>
